#ifndef TIMESTAMP_H
#define TIMESTAMP_H

#include <string>
#include <cstdio>

class TimeStamp
{
public:
    TimeStamp();
    TimeStamp(unsigned int ts);
    void print();
    void print(const char* prompt);
    void setNow();
    unsigned int toInt(){
        return this->m_ts;
    }
    static TimeStamp* now();

private:
    unsigned int getCurrentTime();
    unsigned int m_ts;

public:
    void operator = (TimeStamp x){
        this->m_ts = x.m_ts;
    }
    bool operator > (TimeStamp x){
        return this->m_ts > x.m_ts;
    }
    bool operator < (TimeStamp x){
        return this->m_ts < x.m_ts;
    }

    bool operator == (TimeStamp x){
        return this->m_ts == x.m_ts;
    }

    void operator = (unsigned int x){
        this->m_ts = x;
    }

    bool operator < (unsigned int x){
        return this->m_ts < x;
    }

    bool operator > (unsigned int x){
        return this->m_ts > x;
    }

    bool operator == (unsigned int x){
        return this->m_ts == x;
    }

    bool operator != (unsigned int x){
        return this->m_ts != x;
    }

    void set(unsigned int x){
        this->m_ts = x;
    }

    int hour(){
        return (int)((this->m_ts>>16) / 3600);
    }

    int minute(){
        return (int)((this->m_ts>>16) % 3600 / 60);
    }

    int second(){
        return (int)((this->m_ts>>16) % 60);
    }

    int millisecond(){
        return (int)(this->m_ts&0x000007ff);
    }

    std::string toFileName(){
        char c_file_str[20];
        sprintf(c_file_str,"%02d%02d%02d%03d",
                this->hour(),
                this->minute(),
                this->second(),
                this->millisecond());
        return std::string(c_file_str);
    }

    int toMillisecond();
    int diff(TimeStamp x);
    static int diff(TimeStamp x, TimeStamp y);

};

#endif // TIMESTAMP_H
